Conversation
| -- Check return code first. We don't want source_sh to raise an LmodError, we just print | ||
| -- an LmodWarning stating we couldn't do a proper version compatibility check | ||
| local rc = os.execute("bash -c 'source " .. script .. "'") | ||
| if rc == 0 then |
There was a problem hiding this comment.
For me this does not seem to work. Even though the script exists, the condition always evaluates to false. By adding some debugging statements, I found that rc is a boolean (or nil?), and if rc then works for me.
There was a problem hiding this comment.
https://www.lua.org/pil/22.2.html is not really clear, but my AI friend told me:
In Lua, os.execute() returns different values depending on the Lua version.
✅ Lua 5.2 and newer (5.2, 5.3, 5.4)
os.execute(command) returns three values:
success, exit_type, code = os.execute("your_command")Meaning:
success → true if the command terminated normally, nil otherwise
exit_type → string:
"exit" → program exited normally
"signal" → program was killed by a signal (Unix)
code → numeric:
exit status (if "exit")
signal number (if "signal")
There was a problem hiding this comment.
Lua 5.1 apparently does only return a number...
💡 Portable pattern
If you want code that works across versions:
local r1, r2, r3 = os.execute(cmd) if type(r1) == "number" then -- Lua 5.1 local exit_code = r1 / 256 else -- Lua 5.2+ local success = r1 local exit_code = r3 end
There was a problem hiding this comment.
I'm confused, so I can catch 3 returns, even if the command only returns a single one (i.e. r1)? And this does not lead to errors?
Also: does this change than solve your original issue of this thing always evaluating to false? I guess I then just check exit_code == 0 and that would work accross both, right?
There was a problem hiding this comment.
Yeah, apparently that works in Lua:
function test()
return 42
end
> test()
42
> r1, r2, r3 = test()
> r1
42
> r2
nil
> r3
nil
Checking the exit code should work in that case, indeed.
There was a problem hiding this comment.
Done, can you check that the current version also works for you? (I tested it and it still works for me - I'm pretty sure I'm on Lua 5.1)
There was a problem hiding this comment.
This file will have to be added to the following list to ensure that it gets deployed to cvmfs:
https://github.com/EESSI/software-layer-scripts/blob/main/install_scripts.sh#L210
…ng the get_cuda_driver_script twice, as it's costly. We simply adapt the script to always return a 0 exit, and then do any handling of the case where EESSI_CUDA_DRIVER_VERSION is NOT set by the end in the calling Lmod hook
Fixes #189
First step to fixing #201
Unblocks #200 , which blocks EESSI/software-layer#1462 which blocks EESSI/software-layer#1453 ...
This PR can be modified by modifying the
create_lmodsitepackage.pywith something like: